var loginJs = function(targetObj){
	this.targetObj = targetObj;
	this.init();
	return this;
};

loginJs.prototype={

		init:function(){
			this.targetObj.find("#loginClick").bind("click",this,this.loginClick);
			var that = this;
			//添加回车事件
			document.onkeydown=function(event){
				e = event ? event :(window.event ? window.event : null);
				if(e.keyCode==13){
					if($("#loginRemExit").is(":hidden")){                      //提示框隐藏时触发登录
						that.targetObj.find("#loginClick").trigger("click");
					}else{
						$("#loginRemExit").trigger("click");				   //提示框显示时触发关闭
					}
				}
			};
			//获取系统访问路径
			var proName =  window.location.pathname.substring(1,window.location.pathname.length);
			var proName = "/" +  proName.substring(0,proName.indexOf("/"));
			this.baseApiPath = "http://"+window.location.host + proName + "/";
			$("#loginReminder").hide();
			$("#loginReminder").find("#loginRemExit").bind("click",function(){
				$("#loginReminder").hide("slow");
			});
		},
		/**
		 * 登录
		 */
		loginClick:function(e){
			var that = e.data;
			that.baseApiPath ="http://127.0.0.1:8088/PLWC-Web/";
			var param = new Object();
			//param["dateTime"] = new Date()+"";
			var userAccount = $.trim(that.targetObj.find("input[name='userAccount']").val());
			var password = $.trim(that.targetObj.find("input[name='password']").val());
			if(userAccount.length ===0){
				that.showInfoWindow("用户名不能为空！！");
				return;
			}
			if(password.length ===0){
				that.showInfoWindow("密码不能为空！！");
				return;
			}
			param["userAccount"]=userAccount;
			param["pwd"]=password;
		    $.ajax({
				type:"post",// 使用post方法访问后台
				dataType : "json",// 返回数据的格式
				async: false,
				url : that.baseApiPath + "basSystemUser/login",
				contentType:"application/json",
				data: JSON.stringify(param) ,// 参数
				error: function(e) {
					console.log("error: "+e.name);
					console.log("error: "+e.message);
				},
				success: function(result) { //msg为返回的数据，在这里做数据绑定
					if(result["code"] == 0){
						console.info(result);
						document.cookie="user_c=" +JSON.stringify(result["data"]);
						window.location.href = "home.html";
					}else{
						that.showInfoWindow(result["message"]);
					}
					// if("SUCESS" == result["type"]){
					// 	document.cookie="user_c=" +result["results"];
					//
					// }else{
					// 	that.showInfoWindow(result["message"]);
					// }
				}
			});
		},
		showInfoWindow:function(infoMesg){
			var loginReminder = $("#loginReminder");
			loginReminder.find("#infoText").text(infoMesg);
			loginReminder.show("slow");
		}
};